package com.zwt.freeMarker;

import freemarker.template.Configuration;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by hello on 2017/10/11.
 */
public class FreeMarkerConfigExtend extends FreeMarkerConfigurer {

    @Value("#{configProperties['imgUrl']}")
    private String imgUrl;

    private Map<String,Object> params = new HashMap<>();

    @Override
    public void afterPropertiesSet() throws IOException, TemplateException {
        super.afterPropertiesSet();
        Configuration cfg = this.getConfiguration();
        cfg.setNumberFormat("#");//防止页面输出数字,变成2,000
        //可以添加很多自己的要传输到页面的[方法、对象、值]
        cfg.setDateFormat("yyyy-MM-dd");
        cfg.setDateTimeFormat("yyyy-MM-dd HH:mm:ss");
        cfg.setTimeFormat("HH:mm:ss");
        params.put("imgUrl",imgUrl);
        cfg.setSharedVaribles(params);
    }
    }
